--[[ SLClickConfigLib: Lightweight library to easily handle click config	]]
--[[ Author: Taffu		Rev Date: 30-Dec-10		Rev No: 1.0		 			]]

local MAJOR, MINOR = "SLClickConfigLib-1.0", 1
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end
local function err(msg) ChatFrame1:AddMessage(msg) end

--[[ Common Clicks: LeftButton, RightButton, MiddleButton, Button4, Button5 ]]
--[[ The idea here is to create a handler much like SlashCmdList that procs ]]
--[[ a toggle under specific "click" conditions, including modifiers.     ]]
--[[ Streamlining this in a library should cut down on wasteful snippets 	]]
--[[ throughout the core AddOn files. Will primarily employ toggles.		]]

local inUse

--[[ Check against active clicks and toggle DB item ]]
function lib:ActClick(frame, button, modifier)
	local dbitem = nil
	if inUse[frame] then
		if modifier then
			if inUse[frame][modifier] then
				if inUse[frame][modifier][button] then
					dbitem = inUse[frame][modifier][button].db
				else return end
			else return end
		else
			if inUse[frame][button] then
				dbitem = inUse[frame][button].db
			else return end
		end
	end
	return dbitem
end

--[[ Create & store new click config settings ]]
function lib:NewClickCmd(frame, button, modifier, db)
	if inUse == nil then inUse = {} end
	if inUse[frame] == nil then inUse[frame] = {} end
	if modifier ~= nil then
		if inUse[frame][modifier] == nil then inUse[frame][modifier] = {} end
		if inUse[frame][modifier][button] == nil then inUse[frame][modifier][button] = {} end
		inUse[frame][modifier][button].db = db
	else
		if inUse[frame][button] == nil then inUse[frame][button] = {} end
		inUse[frame][button].db = db
	end
end